<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib prefix="z" uri="/WEB-INF/lib/zerdoor.tld"%>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link rel="stylesheet" media="screen" href="${path}/plugins/validate/validate.css">
    <script src="${path}/plugins/validate/jquery.validate.min.js" type="text/javascript"></script>
    <c:if test="${ sessionScope.language != 'en'}">
        <script src="${path}/plugins/validate/messages_cn.js" type="text/javascript"></script>
    </c:if>


    <style type="text/css">
        .itemName{
            width:200px;border:0; text-align:center; height:32px; line-height:32px; font-size:16px; border-bottom:1px solid #E7E7E7; margin-right:10px;
        }

        .validateMoney{
            color: red;
            font-weight: bold;
        }


    </style>

    <script type="text/javascript">

        /****************************数字日期转换为大写代码 start***************************/
        var chinese = [<spring:message code='taskSigning.message.msg2' />];
        var len = [<spring:message code='taskSigning.message.msg3' />];
        var ydm =[<spring:message code='taskSigning.message.msg4' />];
        function num2chinese(s)
        {
            s=""+s;
            slen = s.length;
            var result="";
            for(var i=0;i<slen;i++)
            {
                result+=chinese[s.charAt(i)];
            }
            return result;
        }
        function n2c(s)
        {
            s=""+s;
            var result="";
            if(s.length==2)
            {
                if(s.charAt(0)=="1")
                {
                    if(s.charAt(1)=="0")return len[0];
                    return len[0]+chinese[s.charAt(1)];
                }
                if(s.charAt(1)=="0")return chinese[s.charAt(0)]+len[0];
                return chinese[s.charAt(0)]+len[0]+chinese[s.charAt(1)];
            }
            return num2chinese(s)
        }
        function bao(s)
        {
            var datePat = /^(\d{2}|\d{4})(\/|-)(\d{1,2})(\2)(\d{1,2})$/;
            var matchArray = s.match(datePat);
            var ok="";
            if (matchArray == null) return false;
            for(var i=1;i<matchArray.length;i=i+2)
            {
                ok+=n2c(matchArray[i]-0)+ydm[(i-1)/2];
            }
            return ok;
        }
        //alert(bao("2004-03-05"))
        /****************************数字日期转换为大写代码 end***************************/

        /********************************金额转换大写 start***************************************/
        var digitUppercase = function(n) {
            var fraction = ['角', '分'];
            var digit = [
                '零', '壹', '贰', '叁', '肆',
                '伍', '陆', '柒', '捌', '玖'
            ];
            var unit = [
                ['元', '万', '亿'],
                ['', '拾', '佰', '仟']
            ];
            var head = n < 0 ? '欠' : '';
            n = Math.abs(n);
            var s = '';
            for (var i = 0; i < fraction.length; i++) {
                s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
            }
            s = s || '整';
            n = Math.floor(n);
            for (var i = 0; i < unit[0].length && n > 0; i++) {
                var p = '';
                for (var j = 0; j < unit[1].length && n > 0; j++) {
                    p = digit[n % 10] + unit[1][j] + p;
                    n = Math.floor(n / 10);
                }
                s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
            }
            return head + s.replace(/(零.)*零元/, '元')
                    .replace(/(零.)+/g, '零')
                    .replace(/^整$/, '零元整');
        };

        /********************************金额转换大写 end***************************************/


        //手续费百分比
        var feePer = ${contract.feePer};
        //推广费百分比
        var proExpensesPer = ${contract.proExpensesPer};

        //日期转换大写
        function dateFormat(date,span){


            if(date == "" || date == undefined){
                return;
            }

            var data = bao(date);

            if(!data){
                $("#" + span).html("");
            }else{
                $("#" + span).html(data);
            }
        }

        function f_moneyFormat(obj,span){

            var data = "";

            var re = /^\d+(?=\.{0,1}\d+$|$)/;
            if (obj.value != "") {
                if (!re.test(obj.value)) {

                    data = "<spring:message code='taskSigning.message.msg5' />";
                    $("#" + span).addClass("validateMoney");
                    obj.focus();
                }else{
                    data = digitUppercase(obj.value);

                    $("#" + span).removeClass("validateMoney");

                    if("total_priceSpan" == span){
                        //处理手续费和推广费
                        f_sxfTgf(obj.value);
                    }
                }
            }else{


                obj.value = 0;
                data = digitUppercase(obj.value);
            }



            $("#" + span).html(data);

        }

        //处理百分比对应数据
        function f_scale(obj,span){


            if(obj == "" || obj == undefined){
                return;
            }

            var data = "";

            var sumMoney = $("#total_price").val();

            var re = /^\d+(?=\.{0,1}\d+$|$)/;
            if (obj.value != "") {
                if (!re.test(obj.value)) {

                    data = "<spring:message code='taskSigning.message.msg6' />";
                    $("#" + span).addClass("validateMoney");
                    obj.focus();
                }else{
                    $("#" + span).removeClass("validateMoney");

                    if(obj.value != 0){


                        data = ((sumMoney * obj.value / 100) - (sumMoney * obj.value / 100 * proExpensesPer / 100) - (sumMoney * obj.value / 100 * feePer / 100)).toFixed(2) + " <spring:message code='taskSigning.message.msg7' />";

                        var scale1 = parseFloat($("#scale1").val());
                        var scale2 = parseFloat($("#scale2").val());
                        var scale3 = parseFloat($("#scale3").val());

                        if((scale1 + scale2 + scale3) > 100){
                            data = "<spring:message code='taskSigning.message.msg8' />";
                            $("#" + span).addClass("validateMoney");
                            obj.focus();
                        }

                    }else{
                        data = 0  + " <spring:message code='taskSigning.message.msg7' />";
                    }


                }
            }else{


                obj.value = 0;
                data = 0  + " <spring:message code='taskSigning.message.msg7' />";
            }



            $("#" + span).html(data );

        }

        $(function(){

            f_init();



        });

        function f_init(){
            $("#frm input").attr("readonly","readonly");
            //初始化数据
            f_moneyFormat($("#total_price").get(0),'total_priceSpan');

            dateFormat($("#start_time").val(),'start_timeSpan');
            dateFormat($("#end_time").val(),'end_timeSpan');
            dateFormat($("#pay_date1").val(),'pay_dateSpan1');
            dateFormat($("#pay_date2").val(),'pay_dateSpan2');
            dateFormat($("#pay_date3").val(),'pay_dateSpan3');

            f_scale($("#scale1").get(0),'scaleSpan1');
            f_scale($("#scale2").get(0),'scaleSpan2');
            f_scale($("#scale3").get(0),'scaleSpan3');

            //绑定选择框事件
            $(".chk_gree").click(function(){

                if(!$(this).attr("checked")){
                    $(this).attr("checked","checked");
                }else{
                    $(this).removeAttr("checked");
                }

            });





        }

     //确认合同
     function f_sureContract(obj){

//         }else{
//             url = "taskSigning/artistSureContract.html";
//         }
         if(!$(".chk_gree").attr("checked")){

             alert("<spring:message code='taskSigning.message.msg9' />");
             return;
         }

         $.post("${path}/taskSigning/artistSureContract.html",
                    {contractId:${contract.contract_id}}
                 ,function(data){


                     if(data == "success"){
                         $(obj).val("<spring:message code='taskSigning.message.msg10' />");
                         $(obj).css("background","#d1d1d1");
                         $(obj).css("cursor","");
                         $(".chk_gree").attr("disabled","disabled");
                         $(obj).unbind("click");

                     }else{
                         alert("<spring:message code='taskSigning.message.msg11' />");
                     }
                 });
     }

        //处理手续费和推广费
        function f_sxfTgf(money){



            var sxf = money * feePer / 100;
            var tgf = money * proExpensesPer / 100;

            $("#shouxufei").html(money + " * " + feePer / 100 + " = " + sxf);
            $("#tuiguangfei").html(money + " * " + proExpensesPer / 100 + " = " + tgf);

            var sxfdx = digitUppercase(sxf);
            var tgfdx = digitUppercase(tgf);

            $("#shouxufeiSpan").html(sxfdx);
            $("#tuiguangfeiSpan").html(tgfdx);


        }



    </script>
</head>
<body>

<!--<img src="upload/qianyue.png" />-->
<div class="signingbox">

    <form id="frm" method="POST">

    <input type="hidden" name="contract_id" value="${contract.contract_id}">


    <h2>${contract.itemName}<spring:message code='taskSigning.message.msg12' /><span><spring:message code='taskSigning.message.msg13' /></span></h2>
    <h3><spring:message code='taskSigning.message.msg14' />${contract.contract_id}</h3>
    <h1><spring:message code='taskSigning.message.msg15' /></h1>

    <div class="signing_contact">
        <ul>
            <li><p><spring:message code='taskSigning.message.msg16' />${contract.baileName}</p><p><label><spring:message code='taskSigning.message.msg17' /></label><input type="text" id="baile_phone" name="baile_phone" value="${contract.baile_phone}" /></p></li>
            <li class="fr"><p><spring:message code='taskSigning.message.msg18' />：${contract.artistName}</p><p><label><spring:message code='taskSigning.message.msg17' /></label><input type="text" id="artist_phone" name="artist_phone" value="${contract.artist_phone}" /></p></li>
        </ul>
    </div>
    <h4>
        <input class="itemName" type="text" id="title" name="title" value="${contract.title}"  /> <spring:message code='taskSigning.message.msg19' />
    </h4>
    <div class="signing_form">
        <dl class="clearfix">
            <dt><spring:message code='taskSigning.message.msg20' /></dt>
            <dd>
                <input type="text" id="total_price" name="total_price" value="${contract.total_price}" class="w_435"
                        onblur="f_moneyFormat(this,'total_priceSpan')"/><spring:message code='taskSigning.message.msg7' />（<spring:message code='taskSigning.message.msg21' /><span id="total_priceSpan"></span>）
            </dd>
        </dl>
        <c:if test="${contract.is_piece == 101001}">
            <dl class="clearfix">
                <dt><spring:message code='taskSigning.message.msg22' /></dt>
                <dd>
                    <input type="text" id="piece_num" name="piece_num" value="${contract.piece_num}"
                           class="w_435"/><spring:message code='taskSigning.message.msg23' />
                </dd>
            </dl>
        </c:if>

        <dl class="clearfix">
            <dt><spring:message code='taskSigning.message.msg24' /></dt>
            <dd>
                <input type="text" id="start_time" name="start_time" value="${contract.start_time}"
                       class="w_435" /><spring:message code='taskSigning.message.msg25' />（<spring:message code='taskSigning.message.msg21' /><span id="start_timeSpan"></span>）
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>&nbsp;</dt>
            <dd>
                <input type="text" id="end_time" name="end_time" value="${contract.end_time}"
                       class="w_435" /><spring:message code='taskSigning.message.msg26' />（<spring:message code='taskSigning.message.msg21' /><span id="end_timeSpan"></span>）
            </dd>
        </dl>

        <dl class="clearfix">
            <dd><spring:message code='taskSigning.message.msg27' /><span id="shouxufei">1</span><spring:message code='taskSigning.message.msg7' />（<spring:message code='taskSigning.message.msg21' /><span id="shouxufeiSpan"></span>）</dd>
        </dl>
        <dl class="clearfix">
            <dd><spring:message code='taskSigning.message.msg28' /><span id="tuiguangfei">1</span><spring:message code='taskSigning.message.msg7' />（<spring:message code='taskSigning.message.msg21' /><span id="tuiguangfeiSpan"></span>）</dd>
        </dl>

        <dl class="clearfix">
            <dd><spring:message code='taskSigning.message.msg29' />
                <c:if test="${contract.total_price > 2000}">3</c:if>
                <c:if test="${contract.total_price <= 2000}">1</c:if>
                <spring:message code='taskSigning.message.msg30' /></dd>
        </dl>

        <dl class="clearfix">
            <dt>&nbsp;</dt>
            <dd class="clearfix">
                <input type="hidden" id="stage_id1" name="stage_id1" value="${contract.itemStage1.stage_id}">
                <label><spring:message code='taskSigning.message.msg31' /></label>
                <input type="text" id="result_claim1" name="result_claim1" value="${contract.itemStage1.result_claim}" class="w_355" />
                <label><spring:message code='taskSigning.message.msg32' /></label>
                <input type="text" id="pay_date1" name="pay_date1" value="${contract.itemStage1.pay_date}" class="w_95" />
                <label><spring:message code='taskSigning.message.msg26' /></label>
                <label>(<spring:message code='taskSigning.message.msg21' /><span id="pay_dateSpan1"></span>),<spring:message code='taskSigning.message.msg33' /></label>
                <input type="text" id="scale1" name="scale1" value="${contract.itemStage1.scale}" class="w_50"
                        onblur="f_scale(this,'scaleSpan1')"/>
                <label>%(<spring:message code='taskSigning.message.msg34' /></label>
                <label ><span id="scaleSpan1">0</span></label>
                <label>).</label>
            </dd>
        </dl>
        <c:if test="${contract.total_price > 2000}">
            <dl class="clearfix">
                <dt>&nbsp;</dt>
                <dd class="clearfix">
                    <input type="hidden" id="stage_id2" name="stage_id2" value="${contract.itemStage2.stage_id}">
                    <label><spring:message code='taskSigning.message.msg35' /></label>
                    <input type="text" id="result_claim2" name="result_claim2" value="${contract.itemStage2.result_claim}" class="w_355" />
                    <label><spring:message code='taskSigning.message.msg32' /></label>
                    <input type="text" id="pay_date2" name="pay_date2" value="${contract.itemStage2.pay_date}" class="w_95"
                           />
                    <label><spring:message code='taskSigning.message.msg26' /></label>
                    <label>(<spring:message code='taskSigning.message.msg21' /><span id="pay_dateSpan2"></span>),<spring:message code='taskSigning.message.msg33' /></label>
                    <input type="text" id="scale2" name="scale2" value="${contract.itemStage2.scale}" class="w_50"
                           onblur="f_scale(this,'scaleSpan2')"/>
                    <label>%(<spring:message code='taskSigning.message.msg34' /></label>
                    <label ><span id="scaleSpan2">0</span></label>
                    <label>).</label>
                </dd>
            </dl>
            <dl class="clearfix">
                <dt>&nbsp;</dt>
                <dd class="clearfix">
                    <input type="hidden" id="stage_id3" name="stage_id3" value="${contract.itemStage3.stage_id}">
                    <label><spring:message code='taskSigning.message.msg36' /></label>
                    <input type="text" id="result_claim3" name="result_claim3" value="${contract.itemStage3.result_claim}" class="w_355" />
                    <label><spring:message code='taskSigning.message.msg32' /></label>
                    <input type="text" id="pay_date3" name="pay_date3" value="${contract.itemStage3.pay_date}" class="w_95"
                           />
                    <label><spring:message code='taskSigning.message.msg26' /></label>
                    <label>(<spring:message code='taskSigning.message.msg21' /><span id="pay_dateSpan3"></span>),<spring:message code='taskSigning.message.msg33' /></label>
                    <input type="text" id="scale3" name="scale3" value="${contract.itemStage3.scale}" class="w_50"
                           onblur="f_scale(this,'scaleSpan3')"/>
                    <label>%(<spring:message code='taskSigning.message.msg34' /></label>
                    <label ><span id="scaleSpan3">0</span></label>
                    <label>).</label>
                </dd>
            </dl>
        </c:if>
        <h3><spring:message code='taskSigning.message.msg37' /></h3>
        <dl class="clearfix">
            <dt>&nbsp;</dt>
            <dd>
                <div class="hetongintro" style="height: 300px; OVERFLOW-Y: auto; ">
                    ${contract.termsContract}
                </div>
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>&nbsp;</dt>
            <dd>
                <input type="checkbox" id="artist_sure" name="" class="chk_gree"
                <c:if test="${contract.artist_sure == 101001}">
                    checked="checked" disabled
                </c:if>

                        /><label for="artist_sure"><spring:message code='taskSigning.message.msg38' /></label>
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>&nbsp;</dt>
            <dd class="qianyue_btn">

                <c:if test="${contract.baile_sure != 101001}">
                    <p><input type="button" id="" style="background:#d1d1d1;" name="" value="<spring:message code='taskSigning.message.msg39' />" class="subntbtn"  /></p>

                </c:if>
                <c:if test="${contract.baile_sure == 101001}">
                    <p><input type="button" id="" style="background:#d1d1d1;" name="" value="<spring:message code='taskSigning.message.msg40' />" class="subntbtn" /></p>
                    <p><label><spring:message code='taskSigning.message.msg41' />${contract.baile_sure_time}</label></p>
                </c:if>


            </dd>

                <dd class="qianyue_btn">
                    <c:if test="${contract.artist_sure == 101001}">

                        <input type="button" id="" name="" style="background:#d1d1d1;" value="<spring:message code='taskSigning.message.msg42' />" class="subntbtn" />
                        <label><spring:message code='taskSigning.message.msg43' />${contract.artist_sure_time}</label>
                    </c:if>
                    <c:if test="${contract.artist_sure != 101001 && contract.baile_sure == 101001}">

                        <input type="button" id="" name="" style="cursor:pointer;" value="<spring:message code='taskSigning.message.msg44' />" class="subntbtn" onclick="f_sureContract(this)"/>

                    </c:if>
                    <c:if test="${contract.artist_sure != 101001 && contract.baile_sure != 101001}">

                        <input type="button" id="" name="" style="background:#d1d1d1;" value="<spring:message code='taskSigning.message.msg44' />" class="subntbtn" />

                    </c:if>
                </dd>



        </dl>
        <dl class="clearfix">
            <dt>&nbsp;</dt>

        </dl>
    </div>
    </form>
</div>

</body>
</html>
